package com.WhiteAlbum2z.jedis.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.time.Duration;

public class JedisConnectionFactory {
    private static final JedisPool jedisPool;

    static {
        //配置连接池
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();

        //最大连接数
        jedisPoolConfig.setMaxTotal(8);

        //最大空闲连接
        jedisPoolConfig.setMaxIdle(8);

        //最小空闲连接
        jedisPoolConfig.setMinIdle(0);

        //设置最长等待时间   ms单位
        jedisPoolConfig.setMaxWait(Duration.ofDays(1));

        //实例化对象
        jedisPool = new JedisPool(jedisPoolConfig, "替换成你的虚拟机地址", 6379, 1000, "替换你自己的redis密码");

    }

    //获取jedis对象
    public static Jedis getJedis(){
        return jedisPool.getResource();
    }

}
